/*   Copyright 2012 Julian Aloofi

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#ifndef TACTICUS_EVENTMANAGER_HPP
#define TACTICUS_EVENTMANAGER_HPP

#include <list>
#include <map>
#include <boost/shared_ptr.hpp>

#include "Exceptions.hpp"
#include "Application/Events/Event.hpp"
#include "Application/Events/IEventListener.hpp"

namespace Tacticus
{

typedef std::pair<Events::EventType, IEventListener*> ListenerPair;

class EventManager
{
private:
    static EventManager *instance;
    std::list<boost::shared_ptr<Event> > eventQueue;
    std::multimap<Events::EventType, IEventListener*> listenerMap;
public:
    static EventManager &getInstance();
    static void destroy();
    void subscribe(IEventListener *eventListener, Events::EventType listenTo);
    void unsubscribe(IEventListener *eventListener, Events::EventType listenTo);
    void queueEvent(boost::shared_ptr<Event> event);
    void fireEvent(boost::shared_ptr<Event> event); // sends the event instantly
    void sendEvents();
private:
    EventManager() {}
    EventManager(const EventManager&) {}
    ~EventManager() {}
};

}

#endif
